package org.example

object scalaFunData1 {
  def main(args: Array[String]):Unit = {
    def func1: Int => Int = (i:Int) => i * 2
    val list1 = List(1,2,3,4,5).map(func1)
    println(list1)
    val s = "scala"
    println(s.toUpperCase)

    val wordList = Array("java","python","scala")
    val upperCaseWorks = wordList.map(_.toUpperCase())
    upperCaseWorks.foreach(println)

    //val result = wordList.map(_.toUpperCase())
    //println(result)
    val numList = List(20,50,70)
    numList.map(t => + 5).foreach(println)
    numList.foreach(t => println(t*2))
    println(numList.head)
    println(numList.tail)
    println(numList.max)
    println(numList.sum)

    val exam = Array(("张三",Array(58,69,72,88)),("李四",Array(49,66,77,88)))
    exam.map(tp => (tp._1,tp._2.max)).foreach(println)
    exam.map(tp => (tp._1,tp._2.map(t => if(t >= 60)1 else 0).sum)).foreach(println)
    exam.map(tp => (tp._1,tp._2.count(_ >= 60))).foreach(println)
    exam.map(tp => (tp._1,tp._2.sum * 1.0 / tp._2.length))foreach(println)

    val arr1=Array(1,2,3,4,5,6)
    arr1.filter(t => if(t %2 == 0) true else false).foreach(println)
    arr1.filter(t => t%2 == 0).foreach(println)
    arr1.filter(_ %2 == 0).foreach(println)

    val arr2 = Array(Array(1,2,3),Array(3,6,9))
    arr2.flatten.foreach(println)
    val arr3 = Array("a,b,c","d,e,f")
    println("==========")
    arr3.flatMap(t => t.split(" ")).foreach(println)
    val arr4 = Array(("a","b"),("c","d"))
    arr4.flatMap(t => Array(t._1,t._2)).foreach(println)
    //   练习题1：将arr5降维，输出（张三，60）、（张三，70）
    val arr5 = Array("张三,60,70,80","李四,50,70,90")
    println("==========")
    arr5.flatMap(t => t.split(" ")).foreach(println)
    println(arr5.head)
    arr5.flatMap(t => t.split(" ")).foreach(println)
  // 将一组字符串进行分词，并保存成单词列表
    val wordArr = List("hello scala","hello python","hello java")
    val wordSplit = wordArr.map(_.split(""))//分词
    val wordFlatten = wordSplit.flatten//扁平
    println(wordFlatten)
    val wordFlatMap = wordArr.flatMap(_.split(" "))
    println(wordFlatMap)

  }

}
